package net.csdn.business.kanban.api.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.csdn.business.kanban.api.facade.KanbanFacade;
import net.csdn.business.kanban.common.domain.PageDto;
import net.csdn.business.kanban.common.domain.request.KanbanAddParam;
import net.csdn.business.kanban.common.domain.request.KanbanQuery;
import net.csdn.business.kanban.common.domain.request.KanbanUpdateParam;
import net.csdn.business.kanban.common.domain.resp.KanbanResp;
import net.csdn.business.kanban.feign.annotation.Inner;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName KanbanController
 * @Description TODO
 * @Author liuzhisheng
 * @Date 2023/9/13
 **/
@Inner
@RestController
@RequestMapping("/api/v1/kanban")
@RequiredArgsConstructor
@Api(tags = "看板")
@Slf4j
public class KanbanController {
    private final KanbanFacade kanbanFacade;
    /**
     * 看板分页列表
     * @param kanbanQuery
     * @return
     */
    @GetMapping
    @ApiOperation(value = "看板分页列表")
    public PageDto<KanbanResp> kanbanList(@Validated @ModelAttribute KanbanQuery kanbanQuery) {
        return kanbanFacade.kanbanList(kanbanQuery);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "看板详情")
    public KanbanResp getKanbanById(@PathVariable("id") String kanbanId) {
        return kanbanFacade.getKanbanById(kanbanId);
    }

    @PostMapping
    @ApiOperation(value = "新建看板")
    public boolean addKanban(@Validated @RequestBody KanbanAddParam param) {
        return kanbanFacade.addKanban(param);
    }

    @PutMapping
    @ApiOperation(value = "编辑看板")
    public boolean updateKanban(@Validated @RequestBody KanbanUpdateParam param) {
        return kanbanFacade.updateKanban(param);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除看板")
    public boolean removeKanban(@PathVariable("id") String kanbanId){
        return kanbanFacade.removeKanban(kanbanId);
    }

    @GetMapping("/count")
    @ApiOperation(value = "看板数量统计")
    public Long kanbanNumber(@RequestParam("orgId") String orgId) {
        return kanbanFacade.kanbanNumber(orgId);
    }
}

